package com.mall.pay.config;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections.MapUtils;
import org.springframework.jdbc.core.JdbcTemplate;

import com.mall.untils.SpringBeanUtil;
import com.mall.untils.cache.CacheUtil;
/* *
 *类名：WxpayConfig
 *功能：基础配置类
 *详细：设置帐户有关信息及返回路径
 *版本：3.4
 * @author lisj
 *修改日期：2016-07-21
 */
public class PayConfig {
	public static String payConfigKey="payConfig";
	public static Map getWxpayConfig(String platform_type, String payType) {
		String key = platform_type + "_" + payType;
		CacheUtil cacheUtil = CacheUtil.getInstance();
		Map<String, Object> payConfigMap = (Map) cacheUtil.getCache(PayConfig.payConfigKey);
		JdbcTemplate jdbcTemplate = (JdbcTemplate) SpringBeanUtil.getBean("jdbcTemplate");
		if (payConfigMap == null) {
			List<Map<String, Object>> queryList = null;
			String sql = "SELECT * FROM tb_pay_config";
			queryList = jdbcTemplate.queryForList(sql);
			payConfigMap = new HashMap<String, Object>();
			for (Map<String, Object> map : queryList) {
				payConfigMap.put(MapUtils.getString(map,"platform_type") + "_" +MapUtils.getString(map,"pay_type"),
						map);
			}
			cacheUtil.setCache(PayConfig.payConfigKey, payConfigMap, -1);
		}
		System.out.println("获取支付配置信息（"+key+"）："+payConfigMap.get(key));
		return (Map) payConfigMap.get(key);
	}

}
